package com.part2.action.system;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.part2.action.common.Config;
import com.part2.beans.News;
import com.part2.beans.Products;
import com.part2.business.function.NewsService;
import com.part2.business.function.ProductsService;

public class IndexUtilAction extends DispatchAction {
	
	private final Log logger = LogFactory.getLog(getClass());
	
	private NewsService newsService;
	private ProductsService productService;
	
	
	
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}
	public void setProductsService(ProductsService productService) {
		this.productService = productService;
	}

	public ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String companyName = Config.readValue("companyName");
		String webSite = Config.readValue("webSite");
		String webName = Config.readValue("webName");
		String copyRight = Config.readValue("COPYRIGHT");
		
		List<News> newsList = newsService.findNewsByType(null);
		List<Products> proList = productService.findProducts(); 
		
		request.setAttribute("newsList", newsList);
		request.setAttribute("proList", proList);

		request.getSession().setAttribute("companyName", companyName);
		request.getSession().setAttribute("webSite", webSite);
		request.getSession().setAttribute("webName", webName);
		request.getSession().setAttribute("COPYRIGHT", copyRight);
		
		return mapping.findForward("index");
	}
}
